// package-activity/pages/activity-edit-cover/index.js
// no ref 没有任何地方引用
const app = getApp();
import { PageReadonlyDataMixins, ManageTargetInfoUpdateMixins, UserInfoUpdateMixins } from '../../../behaviors/page';
import { navBack } from '../../../common/env';

Page({
    mixins: [PageReadonlyDataMixins, ManageTargetInfoUpdateMixins, UserInfoUpdateMixins],
    data: {
        ownerInfo: {},
        activityInfo: {},
    },
    onLoad(options) {
        app.event.addListener('sendActivityInfo', this._handleSendActivity.bind(this));
    },
    onUnload() {
        app.event.removeListener('sendActivityInfo');
    },
    _handleSendActivity(activityInfo) {
        const ownerInfo = this.data.manageTargetInfo;
        this.setData({
            ownerInfo,
            activityInfo,
        });
    },
    handleChangeCover() {
        const { activityInfo } = this.data;
        activityInfo.cover = e.detail;
        this.setData({
            activityInfo,
        });
    },
    handleRemoveCover() {
        const { activityInfo } = this.data;
        activityInfo.cover = '';
        this.setData({
            activityInfo,
        });
    },
    handleSave(e) {
        const { activityInfo } = this.data;
        app.event.trigger('getActivityInfo', activityInfo);
        navBack();
    },
})